package ${package.application}.api;

import ${package.application}.api.request.${entity}CreateRequest;
import ${package.application}.api.request.${entity}QueryRequest;
import ${package.application}.api.request.${entity}UpdateRequest;
import ${package.application}.api.response.${entity}QueryResponse;
import ${package.application}.api.response.${entity}Response;
import ${package.application}.service.${entity}AppService;
import ${package.common}.base.ApiPageResponse;
import ${package.common}.base.ApiResponse;
import ${package.common}.base.Pagination;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

/**
 * ${table.comment!}接口
 *
 * @author ${author}
 * @since ${date}
 */
@RequestMapping(value = "/4.2.0/${entity?lower_case}")
@RestController
@AllArgsConstructor
@Tag(name = "${table.comment!}接口", description = "${table.comment!}接口")
public class ${entity}Api {

    /**
     * ${table.comment!}应用服务
     */
    private final ${entity}AppService ${entity?uncap_first}AppService;

    /**
     * 创建${table.comment!}
     *
     * @param createRequest ${table.comment!}创建对象
     * @return 响应结果
     */
    @PostMapping
    @Operation(summary = "创建${table.comment!}", description = "创建${table.comment!}")
    public ApiResponse<Void> create(@RequestBody @Valid ${entity}CreateRequest createRequest) {
        return ${entity?uncap_first}AppService.create(createRequest);
    }

    /**
     * 根据主键删除${table.comment!}
     *
     * @param ${entity?uncap_first}Id ${table.comment!}主键
     * @return 响应结果
     */
    @DeleteMapping(value = "/{${table.name}_id}")
    @Operation(summary = "根据主键删除${table.comment!}", description = "根据主键删除${table.comment!}")
    public ApiResponse<Void> deleteById(@PathVariable(name = "${table.name}_id") ${idPropertyType} ${entity?uncap_first}Id) {
        return ${entity?uncap_first}AppService.deleteById(${entity?uncap_first}Id);
    }

    /**
     * 根据主键更新${table.comment!}
     *
     * @param ${entity?uncap_first}Id ${table.comment!}主键
     * @param updateRequest ${table.comment!}更新对象
     * @return 响应结果
     */
    @PutMapping(value = "/{${table.name}_id}")
    @Operation(summary = "根据主键更新${table.comment!}", description = "根据主键更新${table.comment!}")
    public ApiResponse<Void> updateById(@PathVariable(name = "${table.name}_id") ${idPropertyType} ${entity?uncap_first}Id,
            @RequestBody @Valid ${entity}UpdateRequest updateRequest) {
        return ${entity?uncap_first}AppService.updateById(${entity?uncap_first}Id, updateRequest);
    }

    /**
     * 根据主键查询${table.comment!}详情
     *
     * @param ${entity?uncap_first}Id ${table.comment!}主键
     * @return 响应结果
     */
    @GetMapping(value = "/{${table.name}_id}")
    @Operation(summary = "根据主键查询${table.comment!}详情", description = "根据主键查询${table.comment!}详情")
    public ApiResponse<${entity}Response> queryById(@PathVariable(name = "${table.name}_id") ${idPropertyType} ${entity?uncap_first}Id) {
        return ${entity?uncap_first}AppService.queryById(${entity?uncap_first}Id);
    }

    /**
     * 分页查询${table.comment!}
     *
     * @param pagination   分页
     * @param queryRequest ${table.comment!}查询对象
     * @return 响应结果
     */
    @GetMapping
    @Operation(summary = "分页查询${table.comment!}", description = "分页查询${table.comment!}")
    public ApiPageResponse<${entity}QueryResponse> query(@Valid Pagination pagination, @Valid ${entity}QueryRequest queryRequest) {
        return ${entity?uncap_first}AppService.query(pagination, queryRequest);
    }
}
